package Server.DataBase;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 
 * @author kobi
 *
 */
public class TUnitQuery extends Query {
	
	public TUnitQuery(){
		super();
	}
	/**
	 * 
	 * @return
	 * @throws SQLException
	 */
	public ArrayList<TUnit> getAllTUnit() throws SQLException{
		setQuery("SELECT * FROM tunit");
		ResultSet rs = execQuery();
		ArrayList<TUnit> array = new ArrayList<TUnit>();
		while (rs.next()){
			TUnit tUnit = new TUnit(rs.getInt(1), rs.getString(2));
			array.add(tUnit);
		}
		return array;
	}
/**
 * 	
 * @return 
 * @throws SQLException
 */
	public ArrayList<TUnit> getTeacherTunit(int idUser) throws SQLException{
		ArrayList<TUnit> array = new ArrayList<TUnit>();
		setQuery("SELECT teachertunit.idteacher, teachertunit.tunit, tunit.unitname FROM teachertunit, tunit " +
				"WHERE idteacher='"+idUser+"' AND teachertunit.tunit=tunit.tunit");
		ResultSet rs = execQuery();
		while (rs.next())
			array.add(new TUnit(rs.getInt(2),rs.getString(3)));
		return array;
	}
}
